/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author hongjun
 */
package num;

import java.util.Random;
/**
 *
 * @author hongjun
 */
public class Tokenizer {

    protected Random random = new Random();    
    
  public Tokenizer(){
      
  }  
    public int getRandom(String var_desc) {
        int min = getMin(var_desc);
        int step = getStep(var_desc);
        int max = getMax(var_desc) + step;
       
        if (step==0) {
//            hint = "Step can not be zero";
            return 0;
        }
        int base = (max - min) / step;         
        return Math.abs(random.nextInt() % base) * step + min;
    }    
    
    
        public int str2int(String str) {
        int g;
        try {
            g = Integer.parseInt(str);
        } catch (NumberFormatException e) {
            g = 0;
//            hint = "a number next time";
        }
        return g;

    }
        
   public String getVariable(String var_desc) {
        String[] temp = var_desc.split(":");
        return temp[0];
    }
   
    public int getMin(String var_desc) { //min:step:max
        String[] temp = var_desc.split(":");
        return  str2int(temp[1]);
    }

    public int getStep(String var_desc) { //min:step:max
        String[] temp = var_desc.split(":");
        return  str2int(temp[2]);
    }

    public int getMax(String var_desc) { //min:step:max
        String[] temp = var_desc.split(":");
        return  str2int(temp[3]);
    }
    public String getTimType(String var_desc) { //min:step:max
        String[] temp = var_desc.split(":");
        if (temp.length>4)
            return  temp[4];
        else
            return "isNumber";
    }
    public String getOrdType(String var_desc) { //min:step:max
        String[] temp = var_desc.split(":");
        if (temp.length>5)
            return  temp[5];
        else
            return "isNumber";
    }  
    public String getFraType(String var_desc) { //min:step:max
        String[] temp = var_desc.split(":");
        if (temp.length>6)
            return  temp[6];
        else
            return "isNumber";
    }  
}
